class Interface {
    /**
     *登录接口
     *
     * @memberof Interface
     * flag先登录后判断是否可以收礼
     */
    login(code, userInfo, self, callback) {
        let data = {
            code: code,
            encryptedData: userInfo ? userInfo.encryptedData : '',
            iv: userInfo ? userInfo.iv : '',
            invite: wx.getStorageSync("invite_id") ? wx.getStorageSync("invite_id") : (wx.getStorageSync("invite_goodsId") ? wx.getStorageSync("invite_goodsId") : 0)
        }
        this.request(true, 'GET', 'Oauth/login', data).then((res) => {
            if (res.data.code == 1) {
                wx.setStorageSync('user_info', res.data.data)
                if (self) {
                    self.userInfo = res.data.data;
                    this.getPersonInfo(self)
                    self.$apply();
                }
                if (callback) {
                    callback(self, self.code);
                }
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     *
     *获取会员用户信息
     * 
     */

    getPersonInfo(self) {
        this.request(true, 'GET', 'User/getUserInfo', {}).then((res) => {
            if (res.data.code == 1) {
                res.data.data.user_money = parseInt(res.data.data.user_money).toFixed(2);
                let userInfo = wx.getStorageSync('user_info');
                userInfo = Object.assign(userInfo, res.data.data)
                wx.setStorageSync('user_info', userInfo)
                if (self) {
                    self.userInfo = userInfo;
                    self.$apply();
                }
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /************************购物车****************************/
    /**
     * 加入购物车
     * @param {上下文} self 
     * @param {参数} -- goods_id:商品ID goods_num:购买数量
     */
    addToCart(self, goods_id, goods_num, msg, show) {
        this.request(false, 'POST', 'Cart/addToCart', {
            goods_id: goods_id,
            goods_num: goods_num
        }).then((res) => {
            if (res.data.code == 1) {
                self.commitShow = false;
                self.$apply();
                if (self.stype == 1) { //1直接购买，2加入购物车
                    wx.showActionSheet({
                        itemList: ['送朋友', '自己买'],
                        success: function (res) {
                            wx.navigateTo({
                                url: '/pages/a_market/order/order?type=' + res.tapIndex
                            })
                        },
                        fail: function (res) {

                        }
                    })
                } else {
                    if (!show) {
                        this.getCartNum(self);
                        msg = msg ? msg : "添加成功";
                        this.success(msg);
                    }
                }
            }
        })
    }
    /**
     * 获取购物车数据
     * @param {上下文} self 
     * 
     */
    getCartList(self) {
        this.request(true, 'GET', 'Cart/getCartList', {}).then((res) => {
            if (res.data.code == 1) {
                self.carData = res.data.data ? res.data.data : [];
                self.addChooseAndEdit(self.carData);
                self.$apply();
            }
        })
    }

    getCartNum(self) {
        this.request(true, 'GET', 'Cart/getCartSum', {}).then((res) => {
            if (res.data.code == 1) {
                self.cartNum = res.data.data.count;
                self.$apply();
            }
        })
    }
    /**
     * 移除购物车商品
     * @param {*} self 
     */
    removeCart(self, params) {
        this.request(true, 'GET', 'Cart/remove', params).then((res) => {
            if (res.data.code == 1) {
                self.$apply();
            }
        })
    }
    /************************商品****************************/
    /**
     * 首页
     * @param {*} self 
     */
    indexData(self) {
        this.request(true, 'GET', 'Mall/getInfo', {}).then((res) => {
            if (res.data.code == 1) {
                self.indexData = res.data.data;
                self.category = res.data.data.category;
                self.recommend = res.data.data.recommend;
                self.$apply();
            }
        })

    }

    /**
     * 商品列表
     * @param {*} self 
     */
    getGoodsList(self, cat_id, pages = 1, num = 8, keyWord, brand_id, min, max) {
        this.request(true, 'GET', 'Goods/getGoodsList', {
            cat_id: cat_id,
            page: pages,
            num: num,
            keywords: keyWord,
            brand_id: brand_id,
            min: min,
            max: max
        }).then((res) => {
            if (res.data.code == 1) {
                res.data.data.forEach(element => {
                    if (element.goods_remark.length > 18) {
                        element.goods_remark = element.goods_remark.substring(0, 18) + '...'
                        console.log(element.goods_remark)
                        console.log(element.goods_remark.length)
                    }
                })
                let dataList = pages == 1 ? [] : self.goodsList;
                self.goodsList = dataList.concat(res.data.data);
                self.$apply();
            }
        })
    }
    /**
     * 商品详情
     * @param {*} self 
     * @param {商品id} goods_id
     */
    getGoodsDetail(self, goods_id) {
        this.request(true, 'GET', 'Goods/getGoodsDetail', {
            goods_id: parseInt(goods_id)
        }).then((res) => {
            if (res.data.code == 1) {
                if (res.data.code == 1) {
                    let datas = res.data.data;
                    if (datas.goods_remark.length > 18) {
                        datas.goods_reamrk = `${datas.goods_remark.slice(0, 18)}...`
                    }
                    self.commentCont = datas.comment_count;
                    self.comment = datas.comment
                    self.goodsDetails = datas;
                    self.article = datas.goods_content;
                    self.banner = datas.photo;
                    //调用通知接口通知组件更新数据
                    self.$apply();

                } else {
                    this.error(res.data.msg)
                }
            }
        })
    }

    /**
     *下订单（自己购买）
     */
    addOrder(self, params) {
        this.request(true, 'POST', 'Buy/addOrder', params).then((res) => {
            if (res.data.code == 1) {
                var payData = res.data.data;
                if (payData.timeStamp) {
                    //调起微信支付
                    this.requestPayment(payData.timeStamp, payData.nonceStr, payData.package, payData.sign).then((res) => {
                        wx.redirectTo({
                            url: '../../a_me/order_list/order_list?type=2'
                        })
                    }, (error) => {
                        wx.redirectTo({
                            url: '../../a_me/order_list/order_list?type=1'
                        })
                    })
                } else {
                    wx.redirectTo({
                        url: '../../a_me/order_list/order_list?type=2'
                    })
                }

                // self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     *下订单（送朋友）
     */
    addSendGiftOrder(self, params) {
        this.request(true, 'POST', 'Buy/addSendGiftOrder', params).then((res) => {
            if (res.data.code == 1) {
                var payData = res.data.data;
                if (payData.timeStamp) {
                    //调起微信支付
                    this.requestPayment(payData.timeStamp, payData.nonceStr, payData.package, payData.sign).then((res) => {
                        this.getCode(payData.order_id);
                    }, (error) => {
                        wx.redirectTo({
                            url: '../../a_me/order_list/order_list?type=1'
                        })
                    })
                } else {
                    this.getCode(res.data.data.order_id);
                }

                // self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 待付款订单
     */
    getUnPaidOrder(self, params) {
        this.request(true, 'GET', 'Buy/getUnPaidOrder', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (!datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    // for (var i = 0; i < datas.length; i++) {
                    //     switch (datas[i].status) {
                    //         case 1:
                    //             datas[i].status = "待付款"
                    //             break
                    //     }
                    //     datas[i].create_time = this.formatTime(datas[i].create_time, 'Y-M-D h:m')
                    // }
                    if (params.page == 1) {
                        self.orderList = datas
                    } else if (datas) {
                        self.orderList = self.orderList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.orderList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 待付款订单详情
     */
    getOrderDetail(self, params) {
        this.request(true, 'GET', 'Buy/getOrderDetail', params).then((res) => {
            if (res.data.code == 1) {
                res.data.data.add_time = this.formatTime(res.data.data.add_time, 'Y.M.D h:m:s')
                self.orderDetails = res.data.data;
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 取消订单
     */
    onBuyCancel(self, params) {
        this.request(true, 'GET', 'Buy/cancel', params).then((res) => {
            if (res.data.code == 1) {
                self.cancelType = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 待付款订单发起支付
     */
    onPay(self, params, type) { //type订单类型：1、送朋友；2、自己购买
        this.request(true, 'GET', 'Buy/pay', params).then((res) => {
            if (res.data.code == 1) {
                var payData = res.data.data;
                //调起微信支付
                if (payData.timeStamp) {
                    this.requestPayment(payData.timeStamp, payData.nonceStr, payData.package, payData.sign).then((res) => {
                        if (type == 1) {
                            this.getCode(res.data.data.order_id);
                        } else {
                            wx.redirectTo({
                                url: '../../a_me/order_list/order_list?type=2'
                            })
                        }
                    }, (error) => {

                    })
                }
                self.$apply()
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 订单状态 2、待发货；3、待收货；4、待评价
     */
    getOrderList(self, params) {
        this.request(true, 'GET', 'Order/getOrderList', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (!datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.orderList = datas
                    } else if (datas) {
                        self.orderList = self.orderList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.orderList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 提醒发货
     */
    onOrderRemind(self, params) {
        this.request(true, 'GET', 'Order/remind', params).then((res) => {
            if (res.data.code == 1) {
                this.success("提醒成功");
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 订单详情
     */
    getDetail(self, params) {
        this.request(true, 'GET', 'Order/getOrderDetail', params).then((res) => {
            if (res.data.code == 1) {
                res.data.data.add_time = this.formatTime(res.data.data.add_time, 'Y.M.D h:m:s')
                var goodsObject = Object.assign(res.data.data, {
                    order_mode: 2,
                });
                self.orderDetails = goodsObject;
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 确认收货
     */
    onOrderConfirm(self, type, params) {
        this.request(true, 'GET', 'Order/receive', params).then((res) => {
            if (res.data.code == 1) {
                if (type == 0) {
                    wx.redirectTo({
                        url: '../../a_me/order_list/order_list?type=4'
                    });
                } else {
                    wx.navigateBack({})
                    wx.redirectTo({
                        url: '../../a_me/order_list/order_list?type=4'
                    });
                }
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 发布评价
     */
    addComment(self, params) {
        this.request(true, 'POST', 'Comment/addComment', params).then((res) => {
            if (res.data.code == 1) {
                this.confirm("谢谢您的评价！", false).then((res) => {
                    wx.navigateBack({})
                })
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 评论列表
     */
    getCommentList(self, params) {
        this.request(true, 'GET', 'Comment/getList', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (!datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].add_time = this.formatTime(datas[i].add_time, 'Y-M-D h:m')
                    }
                    if (params.page == 1) {
                        self.commentList = datas
                    } else if (datas) {
                        self.commentList = self.commentList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.commentList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 我送出的
     */
    mySendOut(self, params) {
        this.request(true, 'GET', 'Gift/mySendOut', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (!datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].create_time = this.formatTime(datas[i].create_time, 'Y-M-D h:m')
                    }
                    if (params.page == 1) {
                        self.orderList = datas
                    } else if (datas) {
                        self.orderList = self.orderList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.orderList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }

        })
    }
    /**
     * 我收到的
     */
    myReceive(self, params) {
        this.request(true, 'GET', 'Gift/myReceive', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (!datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].receive_time = this.formatTime(datas[i].receive_time, 'Y-M-D h:m')
                    }
                    if (params.page == 1) {
                        self.orderList = datas
                    } else if (datas) {
                        self.orderList = self.orderList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.orderList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 申请退货
     */
    returnGoods(self, params) {
        this.request(true, 'GET', 'Order/returnGoods', params).then((res) => {
            if (res.data.code == 1) {
                wx.navigateBack({
                    delta: 2
                })
                self.$apply()
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 礼物提货
     * @param {*} self 
     * @param {*} params 
     */
    pickUpGoods(self, params) {
        this.request(true, 'GET', 'Order/pickUpGoods', params).then((res) => {
            if (res.data.code == 1) {
                wx.redirectTo({
                    url: '../../a_me/order_list/order_list?type=2'
                });
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 在线充值 
     */
    recharge(self, params) {
        this.request(true, 'GET', 'User/recharge', params).then((res) => {
            if (res.data.code == 1) {
                var payData = res.data.data;
                //调起微信支付
                this.requestPayment(payData.timeStamp, payData.nonceStr, payData.package, payData.sign).then((res) => {
                    this.confirm("充值成功！", false)
                }, (error) => {

                })
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 我的代言人
     */
    getReferrals(self, params) {
        this.request(true, 'GET', 'User/referrals', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].reg_time = this.formatTime(datas[i].reg_time, 'Y-M-D h:m')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.groupList = datas
                    } else if (datas) {
                        self.groupList = self.groupList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.groupList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /*******************抽奖******************************* */
    /**
     * 参与抽奖
     * @param {上下文}self
     * @param {上下文}code
     */
    giftJoin(self, send_id, flag) {
        this.request(true, 'POST', 'Lottery/join', {
            send_id: send_id
        }).then((res) => {
            if (res.data.code == 1) {
                this.success('参与成功');
                self.getData();
                self.flagStatus = 0;
            } else {
                this.error(res.data.msg)
            }
            self.$apply();
        })
    }

    /**
     * 判断是否可抽奖
     * @param {上下文}self
     * @param {上下文}code
     * @param {1:平台发起，2：用户发起}type
     */
    giftIsJoin(self, send_id, type) {
        this.request(true, 'GET', 'Lottery/isJoin', {
            send_id: send_id
        }).then((res) => {
            if (res.data.code == 1) {
                self.flagStatus = res.data.data.status;
                self.$apply();
            }
        })
    }

    /**
     * 抽奖信息
     * @param {上下文}self
     * @param {上下文}code
     */
    getLotteryInfo(self, send_id) {
        this.request(true, 'GET', 'Lottery/getLotteryInfo', {
            send_id: send_id
        }).then((res) => {
            if (res.data.code == 1) {

                if (res.data.data.open_type == 3) {
                    self.imgTit = `满${res.data.data.open_num}人自动开奖`
                }
                let date = new Date(res.data.data.open_time * 1000);
                res.data.data.open_time = this.getFormateTime(date)
                if (res.data.data.open_type == 2) {
                    self.imgTit = res.data.data.open_time + "结束"
                }
                if (res.data.data.is_win == 1) {
                    self.win_note = '恭喜你中奖了'
                }
                var goodsNum = 0
                self.datalist = res.data.data;
                self.article = res.data.data.content;
                self.sendNum = goodsNum;
                self.$apply();
            }
        })
    }
    /**
     * 抽奖列表
     * @param {上下文}self
     */
    getLottoryList(self) {
        this.request(true, 'GET', 'Lottery/index', {}).then((res) => {
            if (res.data.code == 1 && res.data.data) {
                for (let [index, value] of res.data.data.entries()) {
                    value.open_time = this.getFormateTime(new Date(value.open_time * 1000))
                    if (value.title.length > 16) {
                        value.title = value.title.slice(0, 16) + '...'
                    }
                }
                self.lottoryList = res.data.data;
                self.$apply();
            }
        })
    }

    /**
     * 抽奖人头像
     * @param {上下文}self
     */
    getUserImg(self, send_id, page, num = 120) {
        this.request(true, 'GET', 'Lottery/getJoinUsers', {
            send_id: send_id,
            page: page,
            num: num
        }).then((res) => {
            if (res.data.code == 1) {
                if (res.data.data.length) {
                    let arr = page == 1 ? [] : self.datalist;
                    arr = arr.concat(res.data.data);
                    self.datalist = arr
                } else {
                    self.page = page
                }
                self.$apply();
            }
        })
    }

    /**
     * 领取礼物
     * @param {上下文}self
     *  @param {code}礼物领取
     */
    isReceive(self, code) {
        this.request(true, 'GET', 'Gift/isReceive', {
            code: code
        }).then((res) => {
            if (res.data.code == 1) {
                if (res.data.data.is_receive == 1) {
                    self.is_receive = res.data.data.is_receive;
                    self.$apply();
                } else {
                    wx.redirectTo({
                        url: `../receive_gift/receive_gift?code=${code}`
                    })
                }

            }
        })
    }
    /**
     * 礼物领取
     * @param {上下文}self
     *  @param {code}礼物领取
     */
    receive(self, code) {
        this.request(true, 'GET', 'Gift/receive', {
            code: code
        }).then((res) => {
            if (res.data.code == 40502) {
                self.msg = res.data.msg;
                self.is_receive = 0;
            } else if (res.data.code == 40501) {
                wx.redirectTo({
                    url: `../receive_gift/receive_gift?code=${code}`
                })
            } else if (res.data.code == 40503) {
                wx.redirectTo({
                    url: `../receive_gift/receive_gift?code=${code}`
                })
            } else if (res.data.code == 1) {
                wx.setStorageSync('flag', 1)
                wx.redirectTo({
                    url: `../receive_gift/receive_gift?code=${code}`
                })
            }

            self.$apply();
            // if (res.data.code == 1 && res.data.data) {
            //     self.$parent.globalData.giftData = res.data.data;
            // } else {
            //     self.is_receive = 0;
            // }
        })
    }
    /**
     * 获取礼物情况
     * @param {上下文}self
     *  @param {code}礼物领取
     */
    getReceiveGifts(self, code) {
        var data = {
            code: code
        }
        this.request(true, 'GET', 'Gift/getReceiveGifts', data).then((res) => {
            if (res.data.code == 1 && res.data.data) {
                res.data.data.goods.forEach(item => {
                    if (item.user.user_id == wx.getStorageSync('user_info').user_id) {
                        res.data.data.status = 10
                        res.data.data.receive_goods_name = item.goods_name;
                        self.receive_id = item.id;
                    }
                });
                self.datalist = res.data.data;
                self.$apply();
            } else {
                this.error(res.data.msg);
            }
        })
    }
    /**
     * 推广记录
     */
    getBrokerage(self, params) {
        this.request(true, 'GET', 'User/brokerage', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].addtime = this.formatTime(datas[i].addtime, 'Y-M-D h:m')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.dataList = datas
                    } else if (datas) {
                        self.dataList = self.dataList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.dataList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 抽奖列表
     */
    getLottery(self, params) {
        this.request(true, 'GET', 'Lottery/index', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].open_time = this.formatTime(datas[i].open_time, 'Y-M-D h:m')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.lottoryList = datas
                    } else if (datas) {
                        self.lottoryList = self.lottoryList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.lottoryList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 我参与的抽奖
     */
    getMyJoin(self, params) {
        this.request(true, 'GET', 'Lottery/myJoin', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].open_time = this.formatTime(datas[i].open_time, 'M月D日 h:m')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.orderList = datas
                    } else if (datas) {
                        self.orderList = self.orderList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.orderList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 
     * 生成二维码
     */
    getQRCode(self, url, callback) {
        this.request(true, 'GET', 'Util/getQRCode', {
            path: url
        }).then((res) => {
            if (res.data.code == 1 && res.data.data) {
                self.codeImg = res.data.data.url;
                self.$apply();
                callback(self);
            }
        })
    }

    /**
     * 代言人信息列表
     */
    getRepresentList(self, params) {
        this.request(true, 'GET', 'Represent/getList', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].addtime = this.formatTime(datas[i].addtime, 'Y-M-D')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.dataList = datas
                    } else if (datas) {
                        self.dataList = self.dataList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.dataList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 信息详情
     */
    getRepresentDetail(self, params) {
        this.request(true, 'GET', 'Represent/getDetail', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                self.article = datas.content;
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 换购列表
     */
    getIntegralList(self, params) {
        this.request(true, 'GET', 'Integral/getList', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].addtime = this.formatTime(datas[i].addtime, 'Y-M-D')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.dataList = datas
                    } else if (datas) {
                        self.dataList = self.dataList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.dataList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 换购列表
     */
    getIntegralExchange(self, params) {
        this.request(true, 'GET', 'Integral/exchange', params).then((res) => {
            if (res.data.code == 1) {
                wx.redirectTo({
                    url: '../../a_me/order_list/order_list?type=2'
                });
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 余额明细
     */
    getMoneyLog(self, params) {
        this.request(true, 'GET', 'User/getMoneyLog', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].create_time = this.formatTime(datas[i].create_time, 'Y-M-D')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.dataList = datas
                    } else if (datas) {
                        self.dataList = self.dataList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.dataList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }

    /**
     * 积分明细
     */
    getPointsLog(self, params) {
        this.request(true, 'GET', 'User/getPointsLog', params).then((res) => {
            if (res.data.code == 1) {
                var datas = res.data.data
                if (datas) {
                    for (var i = 0; i < datas.length; i++) {
                        datas[i].create_time = this.formatTime(datas[i].create_time, 'Y-M-D')
                    }
                }
                if (datas || datas == undefined || datas.length < 10) {
                    self.info_loading = "没有更多了"
                } else {
                    self.info_loading = "正在加载..."
                }
                if (datas != undefined) {
                    if (params.page == 1) {
                        self.dataList = datas
                    } else if (datas) {
                        self.dataList = self.dataList.concat(datas)
                    }
                } else {
                    if (params.page == 1) {
                        self.dataList = []
                    }
                }
                self.isRefresh = true
                self.$apply();
            } else {
                this.error(res.data.msg)
            }
        })
    }
    /**
     * 获取礼物code
     * @param {获取礼物code} code
     */
    getCode(order_id) {
        this.request(true, 'GET', 'Gift/getCode', {
            order_id: order_id
        }).then((res) => {
            if (res.data.code == 1) {
                wx.redirectTo({
                    url: `../../a_luck/send_gift/send_gift?code=${res.data.data.code}`
                })
            }
        })
    }
    getBrandList(self) {
        this.request(true, 'GET', 'Goods/getBrandList', {}).then((res) => {
            if (res.data.code == 1) {
                self.brandList = res.data.data;
                self.$apply();
            }
        })
    }
}
export default Interface